home *** CD-ROM | disk | FTP | other *** search
- set output error
- set display page 23
- set more 1
- #delimit ;
-
- di _n(5) in wh
- " ___ ____ ____ ____ ____ tm" _n
- " /__ / ____/ / ____/" _n
- "___/ / /___/ / /___/ How to Make Tables" _n
- "--------------------------------------------------" _n(2) ;
-
- di in gr
- "This tutorial explores Stata's ability to make tables of counts and summary" _n
- "statistics. All are provided by the '"
- in wh "tabulate" in gr "' command." _n(2)
- "We will be using data on 58 patients, each of whom suffered from one of three"
- _n
- "diseases and each of whom was administered one of four drugs. Recorded along"
- _n
- "with the disease and drug was the change in the patients' systolic blood pres-"
- _n
- "sure." _n(8) ;
-
- #delimit cr
- mac def path
- capture run nullfile.tut
- if _rc {
- mac def path "\stata\"
- capture run %path`nullfile.tut
- if _rc {
- mac def path "/usr/stata/"
- capture run %path`nullfile.tut
- if _rc {
- #delimit ;
- di in red
- "I cannot find the other tutorial files. I have looked in the current" _n
- "directory and in \stata (DOS) or /usr/stata (Unix). Is Stata installed" _n
- "correctly?" _n(2)
- "In any case, I cannot run the tutorial." ;
- #delimit cr
- exit
- }
- }
- }
- macro define F5 "do %path`contents.tut;"
- macro define F6 "do %path`tables.tut;"
- #delimit ;
-
-
- di in wh
- ". use %path`systolic, clear" ;
- noisily use %path`systolic, clear ;
- set more 0 ; more ; set more 1;
-
-
- di _n in wh _dup(79) "-" _n in gr
- "Below, we " in wh "describe" in gr " and " in wh "list"
- in gr " a small amount of our data:" _n
- in wh _dup(79) "-" _n(2)
- ". describe" ;
- noisily describe ;
-
- di in wh _n "list in 1/7" ;
- noisily list in 1/7 ;
- set more 0 ; more ; set more 1 ;
-
-
- di _n(4) in wh _dup(79) "-" _n in gr
- "If you type" _n(2)
- _col(10) in wh "tabulate " in gr "variable-name" _n(2)
- "Stata produces a one-way tabulation of the variable:" _n
- in wh _dup(79) "-" _n(5)
- ". tabulate drug" ;
- di ;
- noisily tabulate drug ;
- di _n ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "If you type" _n(2)
- _col(10) in wh "tabulate " in gr "variable-name variable-name" _n(2)
- "Stata produces a two-way tabulation:" _n
- in wh _dup(79) "-" _n(4)
- ". tabulate drug disease" ;
- noisily tabulate drug disease;
- di _n ; set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata can present a number of variations on the two-way table. The entries"
- _n
- "in the table are controlled by options:" _n(2)
- _col(15) in wh "nofreq" _col(31) in gr "suppress reporting frequencies" _n
- _col(15) in wh "column" _col(31) in gr "report column percentages" _n
- _col(15) in wh "row" _col(31) in gr "report row percentages" _n
- _col(15) in wh "cell" _col(31) in gr "report cell percentages" _n ;
-
- di in gr
- "On the next screen, we repeat the disease by drug table, reporting all the" _n
- "statistics. Notice that we abbreviate the "
- in wh "tabulate" in gr " command, the " in wh "column" in gr " option," _n
- "and even the variable names! Experienced Stata users seldom type out anything."
- _n
- in wh _dup(79) "-" _n(10)
- ". tab dis dr, col row cell" ;
- set more 0 ; more ; set more 1 ;
- noisily tab dis dr, col row cell ;
- set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata can present solely the statistics you want in the table. The table" _n
- "below reports the frequencies and the column percentages:" _n
- in wh _dup(79) "-" _n(3)
- ". tab disease drug, col" ;
- noisily tab disease drug, col ;
- set more 0 ; more ; set more 1 ;
-
- di _n(6) in wh _dup(79) "-" _n in gr
- "Stata can calculate the chi-square statistic for the independence of the" _n
- "rows and columns if we specify the '"
- in wh "chi2" in gr "' option:" _n
- in wh _dup(79) "-" _n(6)
- ". tab disease drug, chi2" ;
- noisily tab disease drug, chi2 ;
- di _n ; set more 0 ; more ; set more 1 ;
-
- di _n(2) in wh _dup(79) "-" _n in gr
- "Stata can make N-way tabulations, too. If you want a three-way tabulation" _n
- "of var1 by var2 by var3, you type:" _n(2)
- in wh
- _col(16) "sort var1" _n
- _col(16) "by var1: tabulate var2 var3" _n(2) in gr
- "Our data doesn't have a third categorical variable, so we won't illustrate" _n
- "this capability." _n
- in wh _dup(79) "-" _n(13) ;
- set more 0 ; more ; set more 1 ;
-
- di _n in wh _dup(79) "-" _n in gr
- "Our data includes the change in the systolic blood pressure for each patient."
- _n
- "We can obtain summary statistics on the systolic variable, by drug, by typing:"
- _n
- in wh _dup(79) "-" _n(6)
- ". tabulate drug, summarize(systolic)" ;
- noisily tabulate drug, summarize(systolic) ;
- di _n(2) ; set more 0 ; more ; set more 1 ;
-
- di _n in wh _dup(79) "-" _n in gr
- "Stata can perform two-way breakdowns, as well. Just as we obtained the fre-"
- _n
- "quencies, we type '"
- in wh "tabulate" in gr "' followed by '"
- in wh "disease drug" in gr "', and then add the" _n
- "'" in wh "summarize(systolic)" in gr "' option:" _n
- in wh _dup(79) "-" _n(18)
- ". tab disease drug, sum(systolic)" ;
- set more 0 ; more ; set more 1 ;
- noisily tab disease drug, sum(systolic) ;
- di ; set more 0 ; more ; set more 1 ;
-
- di _n in wh _dup(79) "-" _n in gr
- "Stata presented a table that reported the mean, standard deviation, and fre-"
- _n
- "quencies. We can control exactly what the table reports using the '"
- in wh "mean" in gr "'," _n
- "'" in white "standard" in gr "', and '" in wh "freq" in gr "' options:" _n
- in wh _dup(79) "-" _n(4)
- ". tab disease drug, sum(systolic) mean" ;
- noisily tab disease drug, sum(systolic) mean ;
- di _n(2) ; set more 0 ; more ; set more 1 ;
-
- di _n in wh _dup(79) "-" _n in gr
- "Stata can make N-way breakdowns of summary statistics, as well. If you" _n
- "wanted to make a three-way table of the summary statistics on 'contvar' by" _n
- "'var1', 'var2', and 'var3', you type:" _n(2) in wh
- _col(16) "sort var1" _n
- _col(16) "by var1: tab var2 var3, sum(contvar)" _n(2) in gr
- "Our data doesn't have a third categorical variable, so we won't illustrate" _n
- "this capability." _n
- in wh _dup(79) "-" _n(13) ;
- set more 0 ; more ; set more 1 ;
-
- drop _all ;
- label drop _all ;
-
- di _n(4) in white
- "Demonstration ends" _n
- "------------------" _n ;
-
- macro define F6 "do %path`regress.tut;" ;
-
- di in green
- "That concludes our short demonstration, but there's much more. We now return"
- _n
- "control to you. Some suggestions:" _n ;
-
- di in green
- "If you ..." _col(34) "Then we will show you ..." _n
- " Press " in white "F5" in green _col(38) "a table of tutorial contents" _n
- " Press " in white "F6" in green _col(38) "the next tutorial, "
- in white "regress.tut" _n ;
-
- run %path`tobuy.tut ;